package cn.jdx.tools;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class 正则提取时间 {
    public static void main(String[] args) {
        String str = "户号:1827748859837 户名:张三 时间:2021-05-20 15:43:11 剩余金额不足,已超过2021-03-03 11:12:30警戒点B,请速续费.";
        List<String> list = run(str);
        System.out.print(list);
    }

    public static List<String> run(String text) {
        String dateStr = text.replaceAll("r?n", " ");
        List<String> list = new ArrayList<String>();
        try {
            Pattern p = Pattern.compile("(\\d{1,4}[-|\\/]\\d{1,2}[-|\\/]\\d{1,2} \\d{1,2}:\\d{1,2}:\\d{1,2})", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE);
            Matcher matcher = p.matcher(dateStr);
            while(matcher.find()) {
                System.out.println(matcher.group());
                list.add(matcher.group());
            }
        } catch (Exception e) {
            return null;
        }
        return list;
    }
}
